package com.white.commonlib.adapter.recycle;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.white.commonlib.R;

import java.util.List;

import butterknife.BindView;

/**
 * Created by yutf on 2017/6/8 0008.
 */

public abstract class BaseRecycleLoadmoreAdapter<T> extends RecycleBaseAdapter<T>
{

    public BaseRecycleLoadmoreAdapter(Context context, List<T> data)
    {
        super(context, data);
    }

    @Override
    public RecyclerView.ViewHolder getCustomHolder(Context context, ViewGroup parent, int viewType, View v)
    {
        return null;
    }

    @Override
    public int getCustomView(int viewType)
    {
        return 0;
    }

    @Override
    public int getLoadMoreView()
    {
        return R.layout.loading_more_layout;
    }

    @Override
    public BaseLoadMoreViewHolder getMoreHolder(ViewGroup parent, View v)
    {
        return new More(v);
    }

    class More extends BaseLoadMoreViewHolder
    {
        LinearLayout layout;
        TextView retry;

        private More(View itemView)
        {
            super(itemView);
            layout = (LinearLayout) itemView.findViewById(R.id.ll_load);
            retry = (TextView) itemView.findViewById(R.id.tv_retry);
            retry.setOnClickListener(new View.OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
                    if (loadMoreListener != null)
                    {
                        setOnLoadingMore();
                        loadMoreListener.loadMore();
                    }
                }
            });
        }

        @Override
        public void onStartLoaddingMore()
        {

        }

        @Override
        public void onLoadingMore()
        {
            layout.setVisibility(View.VISIBLE);
            retry.setVisibility(View.GONE);
        }

        @Override
        public void onLoadFailed()
        {
            layout.setVisibility(View.GONE);
            retry.setClickable(true);
            retry.setText("点击重试");
            retry.setVisibility(View.VISIBLE);
        }

        @Override
        public void onDataDrain()
        {
            layout.setVisibility(View.GONE);
            retry.setClickable(false);
            retry.setText("没有更多数据了~");
            retry.setVisibility(View.VISIBLE);
        }
    }
}
